﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Server
{
    public partial class List_Deny_Program : Form
    {
        public event DenyProcessEventHandler Deny = null;
        public event UnDenyProcessEventHandler Udeny = null;
        public event KiemTra KT;
        int index = -2;
        string name=null;
        public List_Deny_Program()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtThemungdung.Text != "")
            {
                if (KT!=null && KT(txtThemungdung.Text))
                {
                    listView1.Items.Add(txtThemungdung.Text);
                    if (Deny != null)
                    {
                        Deny(this, new ProcessEventArgs(txtThemungdung.Text));
                    }
                    txtThemungdung.Text = "";
                }
                else
                {
                    MessageBox.Show("Chuong trinh "+ txtThemungdung.Text +" da co trong danh sach");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (index != -2 && name != null)
                {
                    Udeny(this, new ProcessEventArgs(name));
                    listView1.Items.RemoveAt(index);
                    index = -2;
                    name = null;
                }
                else
                {
                    MessageBox.Show("Ban chua chon chuong trinh");
                }
            }
            catch
            {
            }
        }
        public void AddProgram(string program)
        {
            listView1.Items.Add(program);
        }

        private void listView1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                name = listView1.GetItemAt(e.X, e.Y).Text;
                index = listView1.GetItemAt(e.X, e.Y).Index;
            }
            catch
            {
            }
        }
    }
}
